//显示对应贷款类型的贷款详情信息
$(function () {
    // var cw = plus.webview.currentWebview();
    var cw = localStorage.getItem('credit-personal');
    localStorage.removeItem('credit-personal');
    cw = JSON.parse(cw);

    console.log(cw.loanId);
    if (cw.loanId) { // 信用贷
        $('.head p span').html(cw.bank + '-');

        var urlDetail = cw.loanId ? "list" : 'info-list'
        $.ajax({
            type: "get",
            url: ur + 'rest/creditLoanController/' + urlDetail,
            async: true,
            dataType: 'json',
            headers: {
                "X-Token": localStorage.token
            },
            data: {
                loanCode: cw.type,
            },
            success: function (res) {
                console.log(res);
                if (res.meta.code == 'S002') {
                    var list = res.data.list;
                    for (var i = 0; i < list.length; i++) {
                        if (list[i].id == cw.loanId) {
                            $('.button').before($('<div class="text">' + HTMLDecode(list[i].graphic) + '</div>'));
                            $('.text').css({
                                'line-height': '2',
                                'margin-top': '1em'
                            });
                        }
                    }
                    /*
                     else {//二押、抵押、垫资、汽车
                     // 这四种用本地图片显示详情
                     var list = res.data;
                     if (list.length != 0) {
                     $('.button').before(HTMLDecode(list[0].graphic));
                     }
                     console.log(JSON.stringify(list))
                     }
                     * */
                } else {
                    mui.toast(res.meta.message);
                }
            }
        });
    } else {
        // 二押、抵押、垫资、汽车
        // 这四种用本地图片显示详情
    }
});

// 普通贷立即申请
$('#askfor').on('tap', function () {
    $.ajax({
        url: ur + 'rest/loanController/getEvaluate',
        type: "get",
        dataType: 'json',
        headers: {
            "X-Token": localStorage.token
        },
        data: {
            loanCode: localStorage.loanCode,
            succ: true
        },
        success: function (data) {
            if (data.meta.code === 'S002') {
                if (data.data.total > 0) {
                    href('select-assess.html', 'select-assess')
                } else { //无评估时
                    mui.toast('请您先进行该项评估！')
                    localStorage.isAssess = localStorage.loanCode //是否评估页过去
                    switch (localStorage.loanCode) {
                        case 'rsbd':
                            href('one-life.html', 'one-life');
                            break;
                        case 'fdyg':
                            href('one-housing.html', 'one-housing');
                            break;
                        case 'ylzy':
                            href('one-professional.html', 'one-professional');
                            break;
                        case 'gsjx':
                            href('one-corporate.html', 'one-corporate');
                            break;
                        case 'fcdy':
                            href('two-house.html', 'two-house');
                            break;
                        case 'qcdy':
                            href('two-car.html', 'two-car');
                            break;
                        /*case 'aj':
                         href('four-aj.html', 'four-aj');
                         break;*/
                        case '2y':
                            href('three-2y.html', 'three-2');
                            break;
                    }
                }
            } else {
                //				mui.toast(data.meta.message);
            }
        }
    })
});

// 转义富文本
function HTMLDecode(text) {
    var temp = document.createElement("div");
    temp.innerHTML = text;
    var output = temp.innerText || temp.textContent;
    temp = null;
    return output;
}